# @Version        : 1.0
# @Create Time    : 2023/7/16 12:42
# @File           : schema_typing.py
# @IDE            : PyCharm
# @Desc           : 自定义数据类型

"""
自定义数据类型 - 官方文档：https://docs.pydantic.dev/dev/concepts/types/#adding-validation-and-serialization
"""

from typing import Annotated
from pydantic import AfterValidator, PlainSerializer, WithJsonSchema
from src.common.typing.validator import (
    datetime_validator,
    date_validator,
    dict_validator,
)
import datetime

DatetimeStr = Annotated[
    str | datetime.datetime | int | float | dict,
    AfterValidator(datetime_validator),
    PlainSerializer(lambda x: x, return_type=str),
    WithJsonSchema({"type": "string"}, mode="serialization"),
]

DateStr = Annotated[
    str | datetime.date | int | float,
    AfterValidator(date_validator),
    PlainSerializer(lambda x: x, return_type=str),
    WithJsonSchema({"type": "string"}, mode="serialization"),
]

DictStr = Annotated[
    str | dict,
    AfterValidator(dict_validator),
    PlainSerializer(lambda x: x, return_type=str),
    WithJsonSchema({"type": "string"}, mode="serialization"),
]
